/**
 * Created by Administrator on 2017/4/12 0012.
 */
import axios from 'axios';
import {API_NEW_VERSION} from '../api';

const FREIGHT_FILES = 'freight/files';
const FREIGHT_APPOINT_ROUTES = '/freight_appoint_routes/admin';
const FREIGHT_ADD_VALUE_ALL = 'freight/addvalues/all';
const FREIGHT_FILE = 'freight/file/';
const FREIGHT_FILE_FIND = API_NEW_VERSION + 'freight/file/find/';
const FREIGHT_BASES = API_NEW_VERSION + 'freight/bases';
const FREIGHT_DETAILS = API_NEW_VERSION + 'freight/details';
const FREIGHT_DETAILS_NO_PAGE = API_NEW_VERSION + 'freight/details/no_page';
const FREIGHT_DETAIL = API_NEW_VERSION + 'freight/detail';
const FREIGHT_BASE = API_NEW_VERSION + 'freight/base/';
// const FREIGHT_DETAILS = API_NEW_VERSION + "freight/details";

const FREIGHT_BASES_MODIFY_STATUS = API_NEW_VERSION + 'freight/bases/modify/status';

var qs = require('qs');

export const moidytFreightBaseStatus = (id, status) => {
  return axios.post(FREIGHT_BASES_MODIFY_STATUS, qs.stringify({id: id, status: status}));
};
export const getFreights = params => {
  return axios.get(API_NEW_VERSION + 'freight/files', {params: params});
};
// 领用记录列表
export const getReceiveList = params => {
  return axios.get(API_NEW_VERSION + '/coupons/' + params.id + '/coupon_logs', {params: params});
};

// 获取时效类型字典
export const getAgeingType = (token, dictCode) => {
  return axios.get('/api/v1.0/admin/fdict_entitys/fdict_entitys?token=' + token + '&dictCode=' + dictCode);
};
// 获取时效范围字典
export const getAgeingRange = (token, dictCode) => {
  return axios.get('/api/v1.0/admin/fdict_entitys/fdict_entitys?token=' + token + '&dictCode=' + dictCode);
};
// 获取时运价类型字典 getFreightType
export const getFreightType = (token, dictCode) => {
  return axios.get('/api/v1.0/admin/fdict_entitys/fdict_entitys?token=' + token + '&dictCode=' + dictCode);
};

/**
 * 获取所有运价增值服务列表
 * @param params
 * @returns {AxiosPromise}
 */
export const getFreightAddValue = (token) => {
  return axios.get(API_NEW_VERSION + FREIGHT_ADD_VALUE_ALL);
};

/**
 * 查询提前预定线路优惠的列表列表
 * @param token
 * @returns {AxiosPromise}
 */
export const searchReservationRuleFreights = params => {
  return axios.get(API_NEW_VERSION + FREIGHT_APPOINT_ROUTES, {params: params});
};
/**
 * 新增运价文件
 * @param params
 * @returns {AxiosPromise}
 */
export const createFreight = (token, params) => {
  return axios.post(API_NEW_VERSION + FREIGHT_FILES, params);
};

/**
 * 根据运价文件id，删除运价文件
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteFreight = id => {
  return axios.delete(API_NEW_VERSION + FREIGHT_FILE + '/' + id);
};

/**
 * 根据运价文件id,更改运价文件状态
 * @param id
 * @param status
 * @returns {AxiosPromise}
 */
export const changeStatus = (id, status) => {
  return axios.post(API_NEW_VERSION + FREIGHT_FILE, qs.stringify({id: id, status: status}));
};

/**
 * 根据运价文件id,查询运价文件详情
 * @param id
 * @returns {AxiosPromise}
 */
export const getFreight = id => {
  return axios.get(FREIGHT_FILE_FIND + '/' + id);
};
/**
 *
 * @param params
 * @returns {AxiosPromise}
 */
export const getFreightBases = params => {
  return axios.get(FREIGHT_BASES, {params: params});
};

/**
 * 新增基础运价文件
 * @param params
 * @returns {AxiosPromise}
 */
export const createFreightBase = params => {
  return axios.post(FREIGHT_BASES, params);
};

/**
 *
 * @param params
 * @returns {AxiosPromise}
 */
export const getFreightDetails = params => {
  return axios.get(FREIGHT_DETAILS_NO_PAGE, {params: params});
};

/**
 * 删除基础详情
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteFreightDetails = params => {
  return axios.delete(FREIGHT_DETAIL, {params: params});
};
/**
 * 删除基础
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteFreightBase = id => {
  return axios.delete(FREIGHT_BASE + id);
};

export const clearFreightBase = id => {
  return axios.delete(API_NEW_VERSION + 'freight/bases/' + id + '/clear');
};

/**
 * 保存基础运价详情表
 * @param params
 * @returns {AxiosPromise}
 */
export const createFreightDetail = params => {
  return axios.post(FREIGHT_DETAILS, params);
};
